// Java Concepts Advanced Placement CS Study Guide
// Cumulative Review 1 Free Response
// Mabel Xu

public class FunNumber
{
	public int numDigits()
	{
		int count = 0;
		int temp = myNum;
		while (temp > 0)
		{
			count++;
			temp /= 10;
		}
		return count;
	}
	
	public int sumDigits()
	{
		int sum = 0;
		String temp = new String(myNum);
		for (int i = 0; i < this.numDigits(); i++)
			sum += new Integer(temp.subString(i, i+1)).intValue();
		return sum;
	}
	
	public boolean isPerfect()
	{
		ArrayList<Integer> factors = new ArrayList<Integer>();
		for (int i = 1; i <= myNum; i--)
			if (myNum % i == 0)
				factors.add(new Integer(i));
		
		Iterator iter = factors.iterator();
		int sum = 0;
		while (iter.hasNext())
			sum += iter.next().intValue();
			
		return sum == myNum;
	}
	
	public FunNumber reverseNum()
	{
		String reverse = new String();
		String temp = new String(myNum);
		for (int i = this.numDigits - 1; i >= 0; i--)
			reverse += temp.subString(i, i+1);
		return (new FunNumber(reverse));
	}
}